<?php
namespace app\api\controller;
use think\Controller;
use app\api\model\Venue;
use app\api\model\Venueappoint;
/**
 * 
 * @author sj
 *测试控制器
 */
class Test extends Controller{
    public function test(){
       //echo json_encode(request()->header());
//        $appkey=request()->header('appkey');
//        $appsecret=request()->header('appsecret');
//        $nonce=request()->header('nonce');
       $appkey=config('Appkey');
       $appsecret=config('AppSecret');
       $time=time();
       $check=sha1($appkey.$appsecret.$time);
       $chekSum=request()->header('checksum');
       if($check!=$chekSum){
           ajaxReturn2(0,'fetfacapzuo','sb');
       }
       //
       echo ajaxReturn2(1,'ok','ok is');
    }
 /**
     * 使用CURL方式发送post请求
     * @param  $url     [请求地址]
     * @param  $data    [array格式数据]
     * @return $请求返回结果(array)
     */
    public function postDataCurl($url='http://www.bd.com/api/test/test',$data=NULL){
       // $this->checkSumBuilder();//发送请求前需先生成checkSum
       $chckSum=sha1(config('Appkey').config('AppSecret').time());
        $timeout = 5000;  
        $http_header = array(
            'CheckSum:'.$chckSum,
            'Content-Type:application/x-www-form-urlencoded;charset=utf-8'
        );
        /**$postdata = '';
        foreach ($data as $key=>$value){
            $postdata.= ($key.'='.$value.'&');
        }**/
        $ch = curl_init(); 
        curl_setopt ($ch, CURLOPT_URL, $url);
        
        if($data!=null){
            curl_setopt ($ch, CURLOPT_POST, 1);
            curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
        }
       
        curl_setopt ($ch, CURLOPT_HEADER, false ); 
        curl_setopt ($ch, CURLOPT_HTTPHEADER,$http_header);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER,false); //处理http证书问题  
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

        $result = curl_exec($ch);  
        var_dump($result);
        if (false === $result) {
            $result =  curl_errno($ch);
        }
        curl_close($ch);    
        return $this->json_to_array($result) ;
    }
    /**
     * 将json字符串转化成php数组
     * @param  $json_str
     * @return $json_arr
     */
    public function json_to_array($json_str){
        if(is_null(json_decode($json_str))){
            $json_str = $json_str;
        }else{
            $json_str = json_decode($json_str);
        }
        $json_arr=array();
    
        foreach($json_str as $k=>$w){
            if(is_object($w)){
                $json_arr[$k]= $this->json_to_array($w); //判断类型是不是object
            }else if(is_array($w)){
                $json_arr[$k]= $this->json_to_array($w);
            }else{
                $json_arr[$k]= $w;
            }
        }
        return $json_arr;
    }
    //传递参数是在浏览器 http://www.bd.com/c_re/username/sj
    public function c_parame(){
        $data=array('username'=>'sj');
        //上面就可以获取到userInfo 
        //然后实例化某一个对象进行传递实例化
       controller('Test')->c_re($data);
        
    }
       public function c_re($data){
          echo "ss";
       }
       public function sj(){
           $vModel=new Venueappoint();
           $vModel->MySelectLists('1','2017.11.9');
           
       }
       public function u(){
         return view();
       }
       public function remo(){
           cookie("user_id",null);
           session('user_id',null);
           session_destroy();
          
       }
}